class_name COtherDataDefine

var m_UUID
var tblAccountInfo: CAccountInfo
var tblFunctionTime: CFunctionTime
var tblForbidIP: CForbidIP
var tblGameSetting: CGameSetting
var tblGameServerInfo: CGameServerInfo
var tblChargeFlow: CChargeFlow
var tblRewardFlow: CRewardFlow
var tblNoticeFlow: CNoticeFlow


static func GetType():
    return TableCommonDefine.EDataDefineType.eDDT_Other


func _init(_uuid, _context):
    m_UUID = _uuid
    self.Reset()


func ClearData():
    # "client none"
    pass


func Reset():
    self.tblAccountInfo = CAccountInfo.new(self.m_UUID)
    self.tblFunctionTime = CFunctionTime.new(self.m_UUID)
    self.tblForbidIP = CForbidIP.new(self.m_UUID)
    self.tblGameSetting = CGameSetting.new(self.m_UUID)
    self.tblGameServerInfo = CGameServerInfo.new(self.m_UUID)
    self.tblChargeFlow = CChargeFlow.new(self.m_UUID)
    self.tblRewardFlow = CRewardFlow.new(self.m_UUID)
    self.tblNoticeFlow = CNoticeFlow.new(self.m_UUID)


func GetUUID():
    return self.m_UUID



func GetDBDefine():
    return null


func GetDataDefineName():
    return "COtherDataDefine"



func UnPack(_bufferStream, _size, _pos):
    assert( _bufferStream.GetDataSize() == _size )
    _bufferStream.SetPosition( _pos )
    var nCount = 0
    var nUUID = 0

    self.tblAccountInfo.UnPack(_bufferStream)
    self.tblFunctionTime.UnPack(_bufferStream)
    self.tblForbidIP.UnPack(_bufferStream)
    self.tblGameSetting.UnPack(_bufferStream)
    self.tblGameServerInfo.UnPack(_bufferStream)
    self.tblChargeFlow.UnPack(_bufferStream)
    self.tblRewardFlow.UnPack(_bufferStream)
    self.tblNoticeFlow.UnPack(_bufferStream)


func GetTableByTableId(_nTblId):
    # var szObjName = 'tbl' .. AllTables[_nTblId]
    # if self[szObjName] == null :
    #     return null
    
    # return self[szObjName]
    return null


func SynFieldData(_nOperType,_tableID, _nDataUUID, _fieldID,  _dataStream, _nBufferSize, _nPos):

    var tbl = self.GetTableByTableId(_tableID)
    if null == tbl :
        return false
    
    if _nOperType == TableCommonDefine.eCTOp_Update:
        var buffStream = CBufferStream.new(null);
        buffStream.Load(_dataStream, _nPos, _nBufferSize)
        return tbl.UnPackField( _fieldID,buffStream, _nBufferSize)
    elif _nOperType == TableCommonDefine.eCTOp_Insert:
        var buffStream = CBufferStream.new(null)
        buffStream.Load(_dataStream, _nPos, _nBufferSize)
        tbl.AddField(_fieldID,buffStream)
        return true
    elif _nOperType == TableCommonDefine.eCTOp_Delete:
        tbl.DelField(_fieldID)
        return true
    elif _nOperType == TableCommonDefine.eCTOp_Assign:
        var buffStream = CBufferStream.new(null)
        buffStream.Load(_dataStream, _nPos, _nBufferSize)
        var nArraySize = buffStream.ReadUint32()
        tbl.SetCurNum(nArraySize)
    
    return false


func AddTableListener(_szTable, _szField, _szCallback, caller):
    var szFunGetTableName = "Get%s" % [ _szTable]
    if not has_method(szFunGetTableName):
        return false
    
    var table = call(szFunGetTableName)
    table.AddEventListener(_szField, _szCallback, caller)


func RemoveTableListener(_szTable, _szField, _szCallback, caller):
    var szFunGetTableName = "Get%s" % [ _szTable]
    if not has_method(szFunGetTableName):
        return false
    
    var table = call(szFunGetTableName)
    table.RemoveEventListener(_szField, _szCallback, caller)

func CopyFrom(_pOther):
    self.m_UUID = _pOther.m_UUID
    self.tblAccountInfo.CopyFrom(_pOther.tblAccountInfo)
    self.tblFunctionTime.CopyFrom(_pOther.tblFunctionTime)
    self.tblForbidIP.CopyFrom(_pOther.tblForbidIP)
    self.tblGameSetting.CopyFrom(_pOther.tblGameSetting)
    self.tblGameServerInfo.CopyFrom(_pOther.tblGameServerInfo)
    self.tblChargeFlow.CopyFrom(_pOther.tblChargeFlow)
    self.tblRewardFlow.CopyFrom(_pOther.tblRewardFlow)
    self.tblNoticeFlow.CopyFrom(_pOther.tblNoticeFlow)



func GetAccountInfo():    
    return self.tblAccountInfo

func GetFunctionTime():    
    return self.tblFunctionTime

func GetForbidIP():    
    return self.tblForbidIP

func GetGameSetting():    
    return self.tblGameSetting

func GetGameServerInfo():    
    return self.tblGameServerInfo

func GetChargeFlow():    
    return self.tblChargeFlow

func GetRewardFlow():    
    return self.tblRewardFlow

func GetNoticeFlow():    
    return self.tblNoticeFlow


